/************************
 * 
 * @author Justin Adams 
 * Student # : 200735090
 * 
 ***********************/
package tttCore;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public final class TextWriter {
	private String filePath;
	private FileWriter fStream;
	private BufferedWriter out;

	public TextWriter(String filePath){
		this.filePath = filePath;
		try {
			boolean exists = new File(filePath).exists();
			if(!exists){
				File F = new File("gameData.txt");
				F.createNewFile();
				fStream = new FileWriter(this.filePath, false);
				out = new BufferedWriter(fStream);
			//	out.write("xIsNotTaken\n");
				out.close();
				out = new BufferedWriter(fStream);
			}
			//	System.out.println("New score writer");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	//does the actual writing
	public void writeToFile(String text){

		try {
			fStream = new FileWriter(this.filePath, false);
			out = new BufferedWriter(fStream);
			out.write(text + ";\n");
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
